<template>
  <div class="app-container">
    <el-card class="box-card" shadow="never">
      <el-row :gutter="20">
        <el-col :span="2"
          ><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="2"
          ><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="2"
          ><el-input size="mini" placeholder="楼宇名称"></el-input>
        </el-col>
        <el-col :span="6">
          <el-button type="primary" size="mini">立即创建</el-button>
          <el-button type="primary" size="mini" @click="handleSearch()">搜索</el-button>
          </el-col
        >
      </el-row>
    </el-card>

    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      style="margin-top: 1%"
    >
    <el-table-column label="id" align="center" width="50">
        <template slot-scope="scope">
          {{ scope.row.id }}- {{ scope.row.room.id }}
        </template>
      </el-table-column>
      <el-table-column label="所属园区" align="center" width="200">
        <template slot-scope="scope">
          {{ scope.row.room.building.park.name }}
        </template>
      </el-table-column>

      <el-table-column label="所属楼宇" align="center">
        <template slot-scope="scope">
          {{ scope.row.room.building.name }}
        </template>
      </el-table-column>

      <el-table-column label="房间号" align="center">
        <template slot-scope="scope">
          {{ scope.row.room.name }}-{{ scope.row.room.id }}
        </template>
      </el-table-column>

      <el-table-column label="企业名称" align="center">
        <template slot-scope="scope">
          {{ scope.row.enterprise!=undefined? scope.row.enterprise.name:'' }}
        </template>
      </el-table-column>

      <el-table-column label="类别" align="center">
        <template slot-scope="scope">
          {{ scope.row.enterprise!=undefined ? scope.row.enterprise.nature:'' }}
        </template>
      </el-table-column>

      <el-table-column label="联系人" align="center">
        <template slot-scope="scope">
          {{ scope.row.user.name }}
        </template>
      </el-table-column>

      <el-table-column label="电话" align="center">
        <template slot-scope="scope">
          {{ scope.row.user.phone }}
        </template>
      </el-table-column>

      <!-- <el-table-column label="人员类型" align="center">
        <template slot-scope="scope">
          {{ scope.row.user.type==1?'内部人员':'外部人员' }}
        </template>
      </el-table-column> -->

      <el-table-column label="性质" align="center" width="80">
        <template slot-scope="scope">
          {{ scope.row.type==1?'个人':'企业' }}
        </template>
      </el-table-column>

      <el-table-column label="租赁面积㎡" align="center" width="80">
        <template slot-scope="scope">
          {{ scope.row.room.area }}
        </template>
      </el-table-column>

      <el-table-column label="收费面积㎡" align="center" width="80">
        <template slot-scope="scope">
          {{ scope.row.leaseArea }}
        </template>
      </el-table-column>


      <el-table-column label="签订租金" align="center" width="80">
        <template slot-scope="scope">
          {{ scope.row.rent }}/{{ scope.row.rentType=='1'?'元/m²/月':'元/月' }}
        </template>
      </el-table-column>
      <el-table-column label="签订物业" align="center" width="80">
        <template slot-scope="scope">
          {{ scope.row.maintenance }} /{{ scope.row. maintenanceType=='1'?'元/m²/月':'元/月' }} 
        </template>
      </el-table-column>

      <el-table-column label="租金支付方式" align="center" width="80">
        <template slot-scope="scope">         
          <el-tag v-if="scope.row.rentPayType==1" type="success">月付</el-tag>
          <el-tag v-if="scope.row.rentPayType==2" type="success">季付</el-tag>
          <el-tag v-if="scope.row.rentPayType==3" type="success">半年付</el-tag>
          <el-tag v-if="scope.row.rentPayType==4" type="success">年付</el-tag>          
        </template>
      </el-table-column>

      <el-table-column label="物业费支付方式" align="center" width="80">
        <template slot-scope="scope">     
          <el-tag v-if="scope.row.maintenancePayType==1" type="success">月付</el-tag>
          <el-tag v-if="scope.row.maintenancePayType==2" type="success">季付</el-tag>
          <el-tag v-if="scope.row.maintenancePayType==3" type="success">半年付</el-tag>
         
          <el-tag v-if="scope.row.maintenancePayType==4" type="success">年付</el-tag>
        </template>
      </el-table-column>

    
      <el-table-column label="租赁状态" width="100" align="center">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.state==1" type="success">租赁中</el-tag>
          <el-tag v-if="scope.row.state==2" type="danger">已退租</el-tag>
          <el-tag v-if="scope.row.state==3">租赁合同签订中</el-tag>           
        </template>
      </el-table-column>      

      <el-table-column label="租赁起止时间" align="center" width="100">
        <template slot-scope="scope">
          {{ scope.row.startDate | formatYmd}} {{ scope.row.endDate | formatYmd}}
        </template>
      </el-table-column>

      <el-table-column align="center" prop="created_at" label="操作" width="200">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            @click="handleDetails(scope.row.id)"
            >详情</el-button
          >
          
          <el-button type="danger" size="mini">删除</el-button>
          <el-button type="success" size="mini" @click="handleGenerate(scope.row.id)">生成账单</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block" style="text-align: center">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="where.currentPage"
        :page-sizes="[10, 15,20, 30, 40]"
        :page-size="where.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
  <script>
import { getLeaseList,getGenerateBill } from "@/api/lease";

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: "success",
        draft: "gray",
        deleted: "danger",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      list: null,
      listLoading: true,
      currentPage4:null,
      where: {
        pageSize: 20,
        currentPage: 1,
        data: {
          state: "",
          roomName: "",
          buildingId: "",
          parkId: "",
          type: "",
          userName: "",
          enterpriseName: "",
          roomType: "",
          nature: "",
        },
        total:0
      },
    };
  },
  created() {
    console.log("123123" + this.where);
    this.fetchData(this.where);
  },
  methods: {
    handleSearch(){
      this.fetchData(this.where);
    },
    fetchData(obj) {
      this.listLoading = true;
      getLeaseList(obj).then((response) => {
        console.log(response);
        this.listLoading = false;
        this.list = response.data;
        this.total = response.count;
      }).catch(error => {
        console.log(error);
        this.listLoading = false;
      });
    },
    handleDetails(id) {
      window.open(this.$router.resolve({ path: '/yuanqu/LeaseDetails' , query: { id: id }}).href, '_blank');
      // this.$router.push({ name: "LeaseDetails", params: { id: id } });
    },
    handleGenerate(id){
      getGenerateBill(id).then((response) => { 
        this.$message('生成账单成功');  
      });
      console.log("handleGenerate");
    },
    handleLease() {
      console.log("handleLease");
      this.$router.push({ name: "LeaseRoom" });
    },
    handleSizeChange(){},
    handleCurrentChange(){},
  },
};
</script>
  